// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Analysis;

public sealed partial class CustomAnalyzer : IAnalyzer
{
	[JsonInclude, JsonPropertyName("char_filter")]
	public ICollection<string>? CharFilter { get; set; }
	[JsonInclude, JsonPropertyName("filter")]
	public ICollection<string>? Filter { get; set; }
	[JsonInclude, JsonPropertyName("position_increment_gap")]
	public int? PositionIncrementGap { get; set; }
	[JsonInclude, JsonPropertyName("position_offset_gap")]
	public int? PositionOffsetGap { get; set; }
	[JsonInclude, JsonPropertyName("tokenizer")]
	public string Tokenizer { get; set; }

	[JsonInclude, JsonPropertyName("type")]
	public string Type => "custom";
}

public sealed partial class CustomAnalyzerDescriptor : SerializableDescriptor<CustomAnalyzerDescriptor>, IBuildableDescriptor<CustomAnalyzer>
{
	internal CustomAnalyzerDescriptor(Action<CustomAnalyzerDescriptor> configure) => configure.Invoke(this);

	public CustomAnalyzerDescriptor() : base()
	{
	}

	private ICollection<string>? CharFilterValue { get; set; }
	private ICollection<string>? FilterValue { get; set; }
	private int? PositionIncrementGapValue { get; set; }
	private int? PositionOffsetGapValue { get; set; }
	private string TokenizerValue { get; set; }

	public CustomAnalyzerDescriptor CharFilter(ICollection<string>? charFilter)
	{
		CharFilterValue = charFilter;
		return Self;
	}

	public CustomAnalyzerDescriptor Filter(ICollection<string>? filter)
	{
		FilterValue = filter;
		return Self;
	}

	public CustomAnalyzerDescriptor PositionIncrementGap(int? positionIncrementGap)
	{
		PositionIncrementGapValue = positionIncrementGap;
		return Self;
	}

	public CustomAnalyzerDescriptor PositionOffsetGap(int? positionOffsetGap)
	{
		PositionOffsetGapValue = positionOffsetGap;
		return Self;
	}

	public CustomAnalyzerDescriptor Tokenizer(string tokenizer)
	{
		TokenizerValue = tokenizer;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CharFilterValue is not null)
		{
			writer.WritePropertyName("char_filter");
			JsonSerializer.Serialize(writer, CharFilterValue, options);
		}

		if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (PositionIncrementGapValue.HasValue)
		{
			writer.WritePropertyName("position_increment_gap");
			writer.WriteNumberValue(PositionIncrementGapValue.Value);
		}

		if (PositionOffsetGapValue.HasValue)
		{
			writer.WritePropertyName("position_offset_gap");
			writer.WriteNumberValue(PositionOffsetGapValue.Value);
		}

		writer.WritePropertyName("tokenizer");
		writer.WriteStringValue(TokenizerValue);
		writer.WritePropertyName("type");
		writer.WriteStringValue("custom");
		writer.WriteEndObject();
	}

	CustomAnalyzer IBuildableDescriptor<CustomAnalyzer>.Build() => new()
	{
		CharFilter = CharFilterValue,
		Filter = FilterValue,
		PositionIncrementGap = PositionIncrementGapValue,
		PositionOffsetGap = PositionOffsetGapValue,
		Tokenizer = TokenizerValue
	};
}